package com.zhouchb.blog.util;

import com.zhouchb.blog.bean.BlogsTags;
import com.zhouchb.blog.bean.Tag;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Zhouchb
 * @Create 2021-09-2021/9/8 :16:48
 * @Description
 */
@Component
public class UtilsTag {

    public List<Long> converToList(String ids) {
        List<Long> list = new ArrayList<>();
        if (ids != null){
            if (ids != "" && ids != null) {
                String[] idarray = ids.split(",");
                for (int i = 0; i < idarray.length; i++) {
                    list.add(new Long(idarray[i]));
                }
            }
        }
        return list;
    }

    public String converTagIds(List<BlogsTags> tags) {
        if (!tags.isEmpty()) {
           StringBuffer tagIds = new StringBuffer();
            boolean flag = false;
            for (int i=0;i<tags.size();i++){
                tagIds.append(tags.get(i).getTagId());
                if (i<tags.size()-1){
                    tagIds.append(",");
                }
            }
   /*         for (BlogsTags tag : tags) {
                if (flag) {
                  tagIds.append(",");
                    flag = false;
                } else {
                    flag = true;
                }
                System.out.println(flag);
                tagIds.append(tag.getTagId());
            }*/
/*            String str = tagIds.toString();
            str = str.replace("[","");
            str = str.replace("]","");*/
            return tagIds.toString();
        }
/*        String tag = tags.toString();
        tag = tag.replace("[","");
        tag = tag.replace("]","");*/
        return "";
    }
}
